package com.zyl.edthresholdtraining.controller;

import com.zyl.edthresholdtraining.common.AppConstant;
import com.zyl.edthresholdtraining.dto.TimeConfigureDTO;
import com.zyl.edthresholdtraining.entity.TimeConfigure;
import com.zyl.edthresholdtraining.service.TimeConfigureService;
import com.zyl.edthresholdtraining.vo.BaseException;
import com.zyl.edthresholdtraining.vo.RichResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author jiangtingfeng
 * @description 时间配置
 * @date 2020/7/31/031
 */
@Controller
@RequestMapping(AppConstant.PROJECT_NAME+"/timeConfigure")
public class TimeConfigureController {

    @Autowired
    private TimeConfigureService timeConfigureService;
    @PostMapping("/modify")
    @ApiOperation("修改时间和次数配置")
    public RichResult addOrUpdate(@RequestBody TimeConfigureDTO timeConfigureDTO) throws BaseException {
        TimeConfigure timeConfigure = new TimeConfigure();
        BeanUtils.copyProperties(timeConfigureDTO,timeConfigure);
        timeConfigureService.remove(null);
        timeConfigureService.save(timeConfigure);
        return new RichResult(timeConfigure);
    }


    @GetMapping("/modify/{name}")
    @ApiOperation(value = "跳到修改各个阶段相应图片的页面")
    public String modify(@PathVariable("name") String name) {
        if ("zyl".equals(name) || "lry".equals(name)) {
            return "modifyTimeConfigure";
        }else {
            return "error";
        }
    }

}
